package gui;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class ThresholdPrefs {

	private static final String PREFS_PATH = "prefs"; 
	
	public static int get(int defaultValue) {
		StringBuilder sb = new StringBuilder();
		try {
			Scanner sc = new Scanner(new File(PREFS_PATH));

			while (sc.hasNext()){
				sb.append(sc.next());
			}
			sc.close();
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return defaultValue;
		}
		
		try {
			return Integer.parseInt(sb.toString());
		} catch (NumberFormatException nfe) {
			nfe.printStackTrace();
			return defaultValue;
		}
	}
	
	public static void set(int value) throws IOException {
		FileWriter fw = new FileWriter(PREFS_PATH);
		fw.write(String.valueOf(value));
		fw.close();
	}
}
